from enum import IntEnum
from dataclasses import dataclass,field
import heapq
import time
from typing import Optional
"""
带双优先级的优先级队列
"""

class Priority(IntEnum):
    """
    Alert最大
    """
    Alert = 0
    Notice = 1
    Text = 2

class Subpriority(IntEnum):
    """
    A最大
    """
    A=0
    B=1
    C=2
    D=3
    E=4

@dataclass(order=True)
class speech_message:
    priority: Priority
    subpriority: Subpriority
    message: str
    
class SpeechPriorityQueue:
    def __init__(self):
        self._heap = []
        self._last_message: Optional[speech_message] = None
    def push(self, message: speech_message):
        if self._last_message and message.message==self._last_message.message:
            return
        heapq.heappush(self._heap, message)
        self._last_message=message
    def pop(self) -> speech_message:
        return heapq.heappop(self._heap)
    def is_empty(self) -> bool:
        return len(self._heap) == 0
    




    
